//
//  NSModelListCell.m
//  Meboo
//
//  Created by kyo on 2023/12/6.
//

#import "NSModelListCell.h"
#import "MBWLMTopicImageModel.h"
@interface NSModelListCell()
@property(nonatomic,strong) UIImageView *vipImageView;
@property(nonatomic,strong) UIImageView *topBackImageView;
@property(nonatomic,strong) UIImageView *iconImageView;
@property(nonatomic,strong) UILabel *titleLab;
@property(nonatomic,strong) UILabel *timeLab;
@property(nonatomic,strong) UILabel *nameLab;
@property(nonatomic,strong) UILabel *interestsLab;
@property(nonatomic,strong) UILabel *tagLab;
@end

@implementation NSModelListCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setModel:(MBWLMTopicModel *)model {
    _model = model;
    MBWLMTopicImageModel *imageModel = model.images[0];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:imageModel.imageUrl] placeholderImage:ImageWithName(@"app_defult_image")];
    self.nameLab.text = [NSString stringWithFormat:@"%@,%@",model.nickName,model.age];
    
    NSString *interestsStr = @"";
    for (MBWLMTopicImageModel *intModel in model.interests) {
        if (interestsStr.length > 0) {
            interestsStr = [NSString stringWithFormat:@"%@, %@",interestsStr,intModel.interest];
        } else {
            interestsStr = [NSString stringWithFormat:@"%@%@",interestsStr,intModel.interest];
        }
    }
    self.interestsLab.text = interestsStr;
}

- (void)setTagStr:(NSString *)tagStr {
    _tagStr = tagStr;
    self.tagLab.text = tagStr;
}

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    self.titleLab.text = [NSString stringWithFormat:@"%@",dict[@"title"]];
    if ([self.titleLab.text containsString:@"XXX"]) {
        self.titleLab.text = [self.titleLab.text stringByReplacingOccurrencesOfString:@"XXX" withString:self.model.nickName];
    }
    self.timeLab.text = [NSString stringWithFormat:@"%@",dict[@"time"]];
}

#pragma mark - Action



#pragma mark - UI
- (void)setupUI {
    self.contentView.backgroundColor = HEXS(@"ffffff");
    self.contentView.layer.cornerRadius = MBHeightScale(15);

    [self.contentView addSubview:self.topBackImageView];
    [self.topBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(MBHeightScale(79));
        make.left.right.top.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.iconImageView];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(9));
        make.top.mas_equalTo(MBHeightScale(18));
        make.width.height.mas_equalTo(MBHeightScale(78));
    }];
    
    [self.contentView addSubview:self.vipImageView];
    [self.vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(MBHeightScale(6));
        make.width.height.mas_equalTo(MBHeightScale(33));
    }];
    
    [self.contentView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView);
        make.left.equalTo(self.iconImageView.mas_right).offset(MBWidthScale(15));
        make.right.mas_equalTo(MBWidthScale(-9));
    }];
    
    [self.contentView addSubview:self.interestsLab];
    [self.interestsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLab.mas_bottom).offset(MBHeightScale(5));
        make.left.equalTo(self.iconImageView.mas_right).offset(MBWidthScale(15));
        make.right.mas_equalTo(MBWidthScale(-9));
    }];
    
    [self.contentView addSubview:self.tagLab];
    [self.tagLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_bottom).offset(MBHeightScale(7));
        make.left.mas_equalTo(MBWidthScale(12));
        make.right.mas_equalTo(MBWidthScale(-12));
    }];
    
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tagLab.mas_bottom).offset(MBHeightScale(8));
        make.left.mas_equalTo(MBWidthScale(12));
        make.right.mas_equalTo(MBWidthScale(-12));
    }];
    
    [self.contentView addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLab.mas_bottom).offset(MBHeightScale(10));
        make.left.mas_equalTo(MBWidthScale(12));
        make.right.mas_equalTo(MBWidthScale(-12));
    }];
    
    
    
    [self.topBackImageView layoutIfNeeded];
    UIBezierPath *maskPath;
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskPath = [UIBezierPath bezierPathWithRoundedRect:self.topBackImageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(MBHeightScale(15),MBHeightScale(15))];//圆角大小
    maskLayer.frame = self.topBackImageView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.topBackImageView.layer.mask = maskLayer;
}

#pragma mark - Setter && Getter

- (UIImageView *)vipImageView {
    if (!_vipImageView) {
        _vipImageView = [UIImageView new];
        _vipImageView.image = ImageWithName(@"modellist_vip_icon");
//        _vipImageView.hidden = YES;
    }
    return _vipImageView;
}

- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [UIImageView new];
        _iconImageView.image = ImageWithName(@"flower_defult");
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        _iconImageView.layer.cornerRadius = MBHeightScale(78/2);
        _iconImageView.layer.borderWidth = 2;
        _iconImageView.layer.borderColor = UIColor.whiteColor.CGColor;
        _iconImageView.layer.masksToBounds = YES;
    }
    return _iconImageView;
}

- (UIImageView *)topBackImageView {
    if (!_topBackImageView) {
        _topBackImageView = [UIImageView new];
        _topBackImageView.image = ImageWithName(@"fashion_cell_topback");
    }
    return _topBackImageView;
}


- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.font = PDRegularScale(12);
        _titleLab.numberOfLines = 2;
        _titleLab.textColor = HEXS(@"666666");
    }
    return _titleLab;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        _timeLab = [UILabel new];
        _timeLab.font = PDRegularScale(12);
        _timeLab.textColor = HEXS(@"999999");
    }
    return _timeLab;
}

- (UILabel *)tagLab {
    if (!_tagLab) {
        _tagLab = [UILabel new];
        _tagLab.font = PDSemiBoldScale(12);
        _tagLab.textColor = HEXS(@"B92176");
    }
    return _tagLab;
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [UILabel new];
        _nameLab.font = PDSemiBoldScale(16);
        _nameLab.textColor = UIColor.whiteColor;
    }
    return _nameLab;
}

- (UILabel *)interestsLab {
    if (!_interestsLab) {
        _interestsLab = [UILabel new];
        _interestsLab.font = PDRegularScale(12);
        _interestsLab.textColor = UIColor.whiteColor;
    }
    return _interestsLab;
}
@end
